package com.lian.hope.mapper;

import com.lian.hope.model.dto.NotificationDTO;
import com.lian.hope.model.po.Notification;
import com.lian.hope.model.vo.NotificationVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NotificationMapper {

    @Select("(select id,content,send_time from notification where receiver_id = #{userId} and notification_type = " +
            "#{notificationType} ) UNION (select id,content,send_time from notification where notification_type = " +
            "#{notificationType} and receiver_id is null)")
    List<NotificationVO> getNotification(Long userId, Integer notificationType);

    @Select("insert into notification(receiver_id,notification_type,content,send_time) values(#{receiverId},#{notificationType},#{content},#{sendTime})")
    void insertNotification(Notification notificationDTO);

    @Select("select id,content,send_time from  notification where receiver_id = #{userId} or receiver_id IS NULL and " +
            "notification_type = 0")
    List<NotificationVO> getSystemNotification(Long userId);

    @Select("select id,content,send_time from  notification where receiver_id = #{userId} or receiver_id IS NULL and " +
            "notification_type = 1")
    List<NotificationVO> getActivityNotification(Long userId);
}
